package Controller.UserController;

import Pojo.User;
import Utils.BaseMessage;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 获取登陆的数据
 */
@WebServlet(name = "UserMsgServlet", urlPatterns = {
        "/api/User/isLogin/UserMsgServlet"
})
public class UserMsgServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("userMsg");
        user.setUserPassword(null);
        response.getWriter().print(JSON.toJSONString(new BaseMessage(0, null, user)));
        return;
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
